<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>建立一个新的 FTP 连接</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.ftp-close.html">ftp_close</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.ftp-delete.html">ftp_delete</a></div>
 <div class="up"><a href="ref.ftp.html">FTP 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.ftp-connect" class="refentry">
   <div class="refnamediv">
    <h1 class="refname">ftp_connect</h1>
    <p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">ftp_connect</span> &mdash; <span class="dc-title">建立一个新的 FTP 连接</span></p>

   </div>
   <div class="refsect1 unknown-seealsp" id="refsect1-function.ftp-connect-unknown-seealsp">
    <h3 class="title">说明</h3>
    <div class="methodsynopsis dc-description">
     <span class="type">resource</span> <span class="methodname"><strong>ftp_connect</strong></span>
      ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$host</code></span>
     [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$port</code></span>
     [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$timeout</code></span>
    ]] )</div>

    <p class="para rdfs-comment">
     如果成功返回一个连接标识，失败则返回 <strong><code>FALSE</code></strong> 。
    </p>
    <p class="para">
     <span class="function"><strong>ftp_connect()</strong></span> 打开一个 FTP 连接，参数
     <em><code class="parameter">host</code></em> 为要连接的服务器。<em><code class="parameter">host</code></em>
     后面不应以斜线结尾，前面也不需要用
     <em>ftp://</em> 开头。可选参数<em><code class="parameter">port</code></em>
     为要连接到的 FTP 器的端口号，如果没有设置或者为0，则会使用默认的端口 21 来连接。
    </p>
    <p class="para">
     可选参数 <em><code class="parameter">timeout</code></em> 用来设置网络传输的超时时间限制。如果此选项留空，则默认的值为 90 秒。超时时间可以在任何时候通过函数 <span class="function"><a href="function.ftp-set-option.html" class="function">ftp_set_option()</a></span>
     及 <span class="function"><a href="function.ftp-get-option.html" class="function">ftp_get_option()</a></span> 来改变和获取。
     <blockquote class="note"><p><strong class="note">Note</strong>: 
      <p class="para">
       参数 <em><code class="parameter">timeout</code></em> 仅适用于 PHP 4.2.0 及以上版本.
      </p>
     </p></blockquote>
    </p>
    <div class="example" id="example-4188">
     <p><strong>Example #1 <span class="function"><strong>ftp_connect()</strong></span> 例子</strong></p>
     <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$ftp_server&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"ftp.example.com"</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">//&nbsp;set&nbsp;up&nbsp;a&nbsp;connection&nbsp;or&nbsp;die<br /></span><span style="color: #0000BB">$conn_id&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">ftp_connect</span><span style="color: #007700">(</span><span style="color: #0000BB">$ftp_server</span><span style="color: #007700">)&nbsp;or&nbsp;die(</span><span style="color: #DD0000">"Couldn't&nbsp;connect&nbsp;to&nbsp;</span><span style="color: #0000BB">$ftp_server</span><span style="color: #DD0000">"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
     </div>

    </div>
    <p class="para">
     参见 <span class="function"><a href="function.ftp-close.html" class="function">ftp_close()</a></span> 和 <span class="function"><a href="function.ftp-ssl-connect.html" class="function">ftp_ssl_connect()</a></span>。
    </p>
   </div>

  </div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.ftp-close.html">ftp_close</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.ftp-delete.html">ftp_delete</a></div>
 <div class="up"><a href="ref.ftp.html">FTP 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
